import * as http from '@/utils/request'
import { BasePageRequest } from '@/models/requests'
import { update } from 'lodash'

const ARTICLE_BASE_URL = '/article'

/** 文章相关请求 */
const ArticleApi = {
  getArticleList: (query: ArticleDto) => {
    return http.getPage<ArticleVo>(`${ARTICLE_BASE_URL}/articleList`, {
      params: query,
    })
  },
  hotArticleList: () => {
    return http.getList<HotArticleVo>(`${ARTICLE_BASE_URL}/hotArticleList`)
  },
  getArticleDetail: (id: number) => {
    return http.getItem<ArticleDetailVo>(`${ARTICLE_BASE_URL}/${+id}`)
  },
  updateArticleViewCount: (id: number) => {
    return http.putForBase(`${ARTICLE_BASE_URL}/updateViewCount/${id}`)
  },
}

export default ArticleApi

/** 请求参数 */
export interface ArticleDto extends BasePageRequest {
  pageNum: 1
  pageSize: 10
  categoryId?: number
}

/** 响应参数 */
export interface ArticleVo {
  categoryId?: number
  content?: string
  createTime?: any
  id?: number
  isComment?: string
  isTop?: string
  status?: string
  summary?: string
  thumbnail?: string
  title?: string
  viewCount?: number
  categoryName?: string
  class_id?: number
}

export interface HotArticleVo {
  id?: number

  title?: string

  viewCount?: number
}

export interface ArticleDetailVo {
  id?: number

  title?: string

  categoryId?: number

  categoryName?: string

  thumbnail?: string

  content?: string

  viewCount?: number

  createTime?: any
}
